package com.atguigu.utils;

import com.atguigu.pojo.User;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;


public class WebUtils {
    /***
     *
     * @param value:替代request是因为request只能在Web层使用,无法在Dao层跟Service层中使用,导致耦合度高
     * @param bean
     */
    public static <T> T copyParamToBean(Map value, T bean){
        try {
            // BeanUtils.populate(request,value);
            BeanUtils.populate(bean,value);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return bean;
    }

    public static int parseInt(String strInt,int defaultValue) {
        try {
            return Integer.parseInt(strInt);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return defaultValue;
    }
}
